package team.seekers.hula.island.post.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.island.post.entity.dto.*;
import team.seekers.hula.auth.service.MindUtils;
import team.seekers.hula.island.post.entity.vo.IslandPostDateListVO;
import team.seekers.hula.island.post.entity.vo.IslandPostInfoVO;
import team.seekers.hula.island.post.entity.vo.IslandPostListVO;
import team.seekers.hula.island.post.service.IslandPostService;

import javax.annotation.Resource;

/**
 * @author ekin
 * @Description GOOD
 * @mood happy
 */
@Controller
@ApiResponseBody
@RequestMapping("/post")
public class PostController {

    @Resource
    private IslandPostService islandPostService;


    @ApiOperation(value = "创建帖子或者存草稿")
    @PostMapping("/markOrDraft")
    public String markOrDraft(@RequestBody IslandPostAddDTO post){
        post.setUserId(MindUtils.getUserId());
        return islandPostService.markOrDraft(post);
    }


    @ApiOperation(value = "分页查询记忆型帖子")
    @GetMapping("/page-memory")
    public PageResult<IslandPostDateListVO> listPostMemory(IslandPostQueryDTO islandPostQueryDTO) {
        islandPostQueryDTO.setUserId(MindUtils.getUserId());
        return islandPostService.pageMemoryPost(islandPostQueryDTO);
    }

    @ApiOperation(value = "分页查询非记忆型帖子")
    @GetMapping("/page")
    public PageResult<IslandPostListVO> pagePost(IslandPostQueryDTO islandPostQueryDTO) {
        islandPostQueryDTO.setUserId(MindUtils.getUserId());
        return islandPostService.pagePost(islandPostQueryDTO);
    }

    @ApiOperation(value = "携带信息发起私信交流")
    @PostMapping("/communication")
    public void communication(@RequestBody IslandPostReplyDTO replyDTO) {
//        islandPostService.articleCommunication(replyDTO);
    }

    @ApiOperation(value = "点赞或取消点赞帖子")
    @GetMapping("/like-or-unlike")
    public void likePost(@RequestParam String id) {
        islandPostService.likeOrUnLike(id);
    }


    @ApiOperation(value = "删除帖子")
    @PostMapping("/delete")
    public void remove(@RequestParam String id) {
        islandPostService.delete(id);
    }


    @ApiOperation(value = "获取帖子详细信息")
    @GetMapping("/info")
    public IslandPostInfoVO queryPost(@RequestParam String id) {
        return islandPostService.info(id);
    }


    @ApiOperation(value = "帖子编辑页查询是否有草稿态")
    @GetMapping("/draft")
    public IslandPostUpdateDTO editPost(@RequestParam String islandId) {
        return islandPostService.editPost(islandId);
    }

    @ApiOperation(value = "获取帖子编辑")
    @GetMapping("/edit")
    public IslandPostUpdateDTO edit(@RequestParam String id){
        return islandPostService.getEditInfo(id);
    }

    @ApiOperation(value = "更新帖子信息")
    @PostMapping("/update")
    public void update(@RequestBody IslandPostUpdateDTO updateDTO){
        islandPostService.updatePost(updateDTO);
    }




}
